package com.xianan.xuhui.netsecurityproject.controller.web;

import com.xianan.xuhui.netsecurityproject.common.ResponseVo;
import com.xianan.xuhui.netsecurityproject.domain.dto.login.LoginInputDto;
import com.xianan.xuhui.netsecurityproject.domain.dto.login.LoginResponseDto;
import com.xianan.xuhui.netsecurityproject.domain.enums.WebClientTypeEnum;
import com.xianan.xuhui.netsecurityproject.service.admin.IPCService;
import com.xianan.xuhui.netsecurityproject.service.web.IUserService;
import com.xianan.xuhui.netsecurityproject.service.web.IWeiXinService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.security.auth.login.LoginContext;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xiaoli
 * @description登录控制器
 * @since 2025/3/25 10:26
 */
@Api(tags = "登录相关")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/web/login")
public class WebLoginController {

    private final IUserService iUserService;
    private final IWeiXinService iWeiXinService;
    private final IPCService iPCService;

    @PostMapping("/login")
    public ResponseVo<LoginResponseDto> login(HttpServletResponse response, @RequestBody LoginInputDto loginInputDto){
        LoginResponseDto loginResponseDto;
        Integer clientType = loginInputDto.getClientType();
        if(WebClientTypeEnum.WX_MINI_PROGRAM.getKey().equals(clientType)){
            //小程序登录
            loginResponseDto=iWeiXinService.login(loginInputDto);
        }else{
            //PC登录
            loginResponseDto=iPCService.login(loginInputDto);
        }
        return new ResponseVo(loginResponseDto);
    }

}
